#define _CRT_SECURE_NO_WARNINGS
#include"lian.h"
void SLprintf(SL* add)
{
	SL* puu = add;
	while (puu)
	{
		printf("%d->",puu->data);
		puu = puu->jie;
	}
	printf("NULL\n");
}
SL* xinjie(leixing x)
{
	SL* a = (SL*)malloc(sizeof(SL));
	if (a == NULL)
	{
		perror("malloc fall");
		exit(1);
	}
	a->data = x;
	a->jie = NULL;
	return a;
}
void SLweicha(SL** add,leixing x)
{
	assert(add);
	SL* a = xinjie(x);
	if (*add == NULL)
	{
		*add = a;
	}
	else
	{
		SL* puu = *add;
		while (puu->jie)
		{
			puu = puu->jie;
		}
		puu->jie = a;
	}
}
void SLtoucha(SL** add, leixing x)
{
	assert(add);
	SL* a = xinjie(x);
	if (*add == NULL)
	{
		*add = a;
	}
	else
	{
		
		a->jie = *add;
		*add = a;
	}
}
void SLweixiao(SL** add)
{
	assert(add&&*add);
	SL* arr1 = *add;
	SL* arr2 = *add;
	if ((*add)->jie == NULL)
	{
		free(*add);
		*add = NULL;
	}
	else
	{
		while (arr2->jie)
		{
			arr1 = arr2;
			arr2 = arr2->jie;
		}
		free(arr2);
		arr2 = NULL;
		arr1->jie = NULL;
	}
}
void SLtouxiao(SL** add)
{
	assert(add && *add);
	SL*arr= (*add)->jie;
	free(*add);
	*add = arr;
}
SL* SLcahzhao(SL* add, leixing x)
{
	assert(add);
	SL* arr = add;
	while (arr)
	{
		if (arr->data == x)
		{
			return arr;
		}
		arr = arr->jie;
	}
	return NULL;
}
SL* SLQzhicha(SL** add, SL* zhi, leixing x)
{
	assert(add && *add);
	assert(zhi);
	SL* xin = xinjie(x);
	if (*add == zhi)
	{
		SLtoucha(add, x);
	}
	else
	{
		SL* arr = *add;
		while (arr->jie != zhi)
			{
				arr = arr->jie;
			}
			xin->jie = zhi;
			arr->jie = xin;
	}	
}
SL* SLHzhicha(SL* zhi, leixing x)
{
	assert(zhi);
	SL* arr = zhi;
	SL* xin= xinjie(x);
	xin->jie = arr->jie;
	arr->jie = xin;
}
SL* SLzhishan(SL** add, SL* zhi)
{
	assert(add && *add);
	assert(zhi);
	if (*add == zhi)
	{
		SLtouxiao(add);
	}
	else
	{
		SL* arr = *add;
		while (arr->jie != zhi)
		{
			arr = arr->jie;
		}
		arr->jie = zhi->jie;
		free(zhi);
		zhi = NULL;
	}	
}
SL* SLHzhishan(SL* zhi)
{
	assert(zhi&&zhi->jie);
	SL*arr = zhi->jie;
	zhi->jie = arr->jie;
	free(arr);
	arr = NULL;
}
SL* SLxiaohui(SL** add)
{
	assert(add && *add);
	SL* arr = *add;
	while (arr)
	{
		SL* time = arr->jie;
		free(arr);
		arr = time;
	}
	*add = NULL;
}